import java.net.*;
import java.io.*;
import java.util.*;
public class IssueClient{
    public static void main(String[] args){
        Socket s = null;
        String ip = "127.0.0.1";
        int serverPort = 7896;
        int requestid= (int)System.currentTimeMillis() / 1000;
        System.out.print("id를 입력하세요 : ");
        Scanner scan = new Scanner(System.in);
        String id = scan.next();

        long sum=0;
        String m ;

        try{
            while(true){
                m = menu_print(id);
                if(m.equals("exit")){
                    System.exit(0);
                }else if(m.equals("else")){
                    System.out.println("잘못입력하셧습니다");
                }else{
                    s = new Socket(ip,serverPort);
                    DataInputStream in = new DataInputStream(s.getInputStream());
                    DataOutputStream out = new DataOutputStream(s.getOutputStream());
                    m = "requestid=" + requestid +"\n"+ m;
                    out.writeUTF(m);
                    String data = in.readUTF();
                    StringTokenizer tokens = new StringTokenizer( data, "\n" );
                    String tmp="";
                    String tmp1="";
                    for( int x = 1; tokens.hasMoreElements(); x++ )
                    {
                        tmp1 =  tokens.nextToken() + "\n";
                        if(x > 3 )
                            tmp =  tmp + tmp1;

                    }
                    System.out.println(tmp);
                }
            }
        }catch(UnknownHostException e){
            System.out.println("host error" + e.getMessage());
        }catch(EOFException e){
            System.out.println("EOF error" + e.getMessage());
        }catch(IOException e){
            System.out.println("IO error" + e.getMessage());
        }finally{
            if(s!= null)
                try{
                    s.close();
                }catch(IOException e){}
        }
    }
    public static String menu_print(String id){
        System.out.println("===>메뉴번호를 입력해주세요<===");
        System.out.println("1.이슈등록 2.이슈삭제 3.이슈리스트 4.이슈변경 5.종료");
        System.out.print("입력 : ");

        String msg="";
        Scanner scan = new Scanner(System.in);
        int data=0;
        try{
            data = scan.nextInt();
        }catch(Exception e){
            msg = "else";
        }
        //String m = "get_string=3";
        if(data == 1){
            System.out.println("=이슈를 등록합니다 ");
            System.out.print("이슈를 입력해주세요 : ");
            String issue = scan.next();
            System.out.print("상태를 입력해주세요 : ");
            String status = scan.next();
            msg = "put_issu=" + id + ":" +status + ":" + issue;
            //String m = "put_issu=nan1004au:start:뭘까요";
        }else if(data == 2){
            System.out.println("=이슈를 삭제합니다 ");
            System.out.print("이슈번호를 입력해주세요 : ");
            String idx = scan.next();
            msg =  "del_issue="  + idx;
            //String m = "del_issue=2";
        }else if(data == 3){
            System.out.println("=이슈를 리스트를 출력합니다 ");
            msg = "get_list="+id;
            //String m = "get_list";
        }else if(data == 4){
            System.out.println("=이슈의 상태를 변경합니다");
            System.out.print("이슈번호를 입력해주세요 : ");
            String idx = scan.next();
            System.out.print("상태를 입력해주세요 : ");
            String status = scan.next();
            msg = "ch_issue=" + idx + ":" + status;
            //String m = "ch_issue=3:fix";
        }else if(data == 5){
            msg = "exit";
        }else{
            msg = "else";
        }
        return msg;
    }
}

